package com.jingdun.sport.api.controller;

import com.google.common.collect.Maps;
import com.jingdun.sport.bean.app.param.SendSmsParam;
import com.jingdun.sport.bean.enums.SmsType;
import com.jingdun.sport.security.util.SecurityUtils;
import com.jingdun.sport.service.SmsLogService;
import com.jingdun.sport.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/sms")
@Api(tags = "发送注册验证码接口")
public class PhoneCodeController {

    @Autowired
    private SmsLogService smsLogService;

    @Autowired
    private UserService userService;

    /**
     * 发送验证码接口
     */
    @PostMapping("/send")
    @ApiOperation(value = "发送注册验证码", notes = "用户的发送注册验证码")
    public ResponseEntity<Void> audit(@RequestBody SendSmsParam sendSmsParam) {
        String userId = SecurityUtils.isUser() ? SecurityUtils.getUser().getUserId() : sendSmsParam.getMobile();
        smsLogService.sendSms(SmsType.instance(sendSmsParam.getMsgType()), userId, sendSmsParam.getMobile(), Maps.newHashMap());
        return ResponseEntity.ok().build();
    }
}